import requests
from bs4 import BeautifulSoup

head = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"}

with open("movie_titles.txt", "w", encoding="utf-8") as file:
    for num in range(0, 250, 25):

        html = requests.get(f"https://movie.douban.com/top250?start={num}", headers=head).text
        soup = BeautifulSoup(html, "html.parser")

        all_titles = soup.find_all("span", attrs={"class": "title"})

        for title in all_titles:
            result = title.string
            if "/" not in result:
                file.write(result + "\n")

